import React, { Component } from 'react';
import qs from 'qs';
import autoBind from 'react-autobind';
import { connect } from 'dva';

// widget 
import HeadNav from '../components/Common/HeadNav'
import SearchResult from '../components/Search/SearchResult'

class CategoryDetailPage extends Component {
	constructor(props) {
        super(props)
        autoBind(this)
    }
    componentDidMount() {
    	const { dispatch, location } = this.props
        let searchParm = this.getSearch()

        if(searchParm.keywords) {
        	dispatch({
	    		type: 'meyley/searchProduction',
	    		payload: {
	    			keywords: searchParm.keywords
	    		}
	    	})	
        }
    }
    getSearch() {
    	const { location } = this.props
        let searchParm = location.search.replace('?', '')
        searchParm = qs.parse(searchParm)
        return searchParm
    }
   	
	render() {
		let searchParm = this.getSearch()
		return (
		  	<div>
                <HeadNav title={searchParm.keywords || 'No Search Key'} leftPath="/category" />
                <SearchResult keywords={searchParm.keywords} {...this.props} />
		    </div>
		);
	}
}

CategoryDetailPage.propTypes = {
};

export default connect(({ meyley, address }) => ({
	meyley,
    address
}))(CategoryDetailPage);